<?php
 /**
 * Date
 * Samble Date class file.
 *
 * @author Lim Afriyadi
 * @version pre-alpha
 * @package Samble
 * @subpackage date
 * @license GNU/GPL.
 */
class SambleDate
{
    const DAY   = 0;
    const MONTH = 1;
    const YEAR  = 2;
    /**
     * Find a date of predefined date substracted by certain
     * o_Value of time amount.
     *
     * @param string $s_Date English writen date.
     * @param int $o_Value Substraction o_Value.
     * @param int $i_Selection Substraction o_Value amount.
     * @return string
     */
    public function substract($s_Date, $o_Value, $i_Selection=0)
    {
        switch($i_Selection)
        {
            case self::DAY:
                $i_Time = strtotime($s_Date.' - '.$o_Value.' day');
                break;
            case self::MONTH:
                $i_Time = strtotime($s_Date.' - '.$o_Value.' month');
                break;
            case self::YEAR:
                $i_Time = strtotime($s_Date . ' - ' . $o_Value . ' year');
                break;
        }
        return date('d-m-Y',$i_Time);
    }
    /**
     * Find a date of predefined date added by certain
     * o_Value of time amount.
     *
     * @param string $s_Date English writen date.
     * @param int $o_Value Substraction o_Value.
     * @param int $i_Selection Substraction o_Value amount.
     * @return string
     */
    public function add($s_Date, $o_Value, $i_Selection=0)
    {
        switch($i_Selection)
        {
            case self::DAY:
                $i_Time = strtotime($s_Date . ' + ' . $o_Value . ' day');
                break;
            case self::MONTH:
                $i_Time = strtotime($s_Date . ' + ' . $o_Value . ' month');
                break;
            case self::YEAR:
                $i_Time = strtotime($s_Date . ' + ' . $o_Value . ' year');
                break;
        }
        return date('d-m-Y',$i_Time);
    }
    /**
     * Find a span of time between two predefined dates.
     *
     * @param int $s_Date_1 First date o_Value.
     * @param int $s_Date_2 Second date o_Value.
     * @return array
     */
    public function getTimeSpan($s_Date_1, $s_Date_2)
    {
        $i_Time_1 = strtotime($s_Date_1);
        $i_Time_2 = strtotime($s_Date_2);
        $i_Span   = 0;
        ($i_Time_1 > $i_Time_2) ?
            $i_Span = $i_Time_1 - $i_Time_2 :
            $i_Span = $i_Time_2 - $i_Time_1;

        $i_Days    = intval($i_Span / 86400);
        $i_Span   = $i_Span % 86400;
        $i_Hours   = intval($i_Span / 3600);
        $i_Span   = $i_Span % 3600;
        $i_Minutes = intval($i_Span / 60);
        $i_Seconds   = $i_Span % 60;
        return array(
            'seconds'=>$i_Seconds,
            'minutes'=>$i_Minutes,
            'hours'=>$i_Hours,
            'days'=>$i_Days
        );
    }
}
?>
